package com.example.p213;

import com.example.p213.calculator.Calculator;
import com.example.p213.calculator.Operation;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Collection;

@SpringBootApplication
public class P213Application {

    public static void main(String[] args) throws IllegalArgumentException {
        ApplicationContext ctx = SpringApplication.run(P213Application.class, args);

        Calculator calculator = ctx.getBean(Calculator.class);
        calculator.calculate(137, 21, '+');
        calculator.calculate(137, 21, '*');
       // calculator.calculate(137, 21, '-');

    }

    //工厂方法
    @Bean
    public Calculator calculator(Collection<Operation> operations) {
        return new Calculator(operations);
    }

    @Bean
    public ApplicationRunner calculationRunner(Calculator calculator) {
        return args -> {
            calculator.calculate(137, 21, '+');
            calculator.calculate(137, 21, '*');
            //calculator.calculate(137, 21, '-');
        };
    }
}
